package com.emcom.gotour.mvc.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.emcom.gotour.enums.TourType;
import com.emcom.gotour.mvc.message.DetailViewMessage;
import com.emcom.gotour.mvc.message.MenuMessage;
import com.emcom.gotour.mvc.view.DetailView;
import com.emcom.gotour.mvc.view.MenuView;
import com.emcom.gotour.mvc.view.SchedulerContentView;
import com.emcom.gotour.mvc.view.TourContentView;
import com.emcom.gotour.po.TourContent;
import com.emcom.gotour.service.TourContentService;
import com.emcom.gotour.vo.ChatVO;
import com.emcom.gotour.vo.TourContentVO;

@Controller
public class DetailController {

	@Autowired
	private TourContentService tourContentService;

	@Autowired
	private MessageSource messageSource;

	@Autowired
	private ChatVO chat;

	@RequestMapping(value={"/detail.html"})
	public void detail(HttpServletRequest request) {
		List<TourContent> popularList = tourContentService.queryPopularContent();
		TourContentVO tourContentVO = tourContentService.queryContent(Long.valueOf(request.getParameter("id")));
		DetailView view = new DetailView();
		view.setTitle(DetailViewMessage.Title.value(request, messageSource));
		view.setTypeImageUrl(MenuMessage.valueOf(TourType.valueOf(tourContentVO.getTypeId()).getMessage().name().concat("_IMAGE_URL")).value(request, messageSource));
		view.setScheduler(DetailViewMessage.Scheduler.value(request, messageSource));
		view.setTourContent(tourContentVO);
		view.setPopularList(popularList);
		view.setTourContentView(new TourContentView(request, messageSource));
		view.setSchedulerContentView(new SchedulerContentView(request, messageSource));
		view.setMenuView(new MenuView(request, messageSource));
		request.setAttribute("view", view);
		request.setAttribute("chat", chat);
	}

}
